package Servlet;

import Pojo.Msgpojo;
import Service.Serviceimpl.Manageserviceimpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

//公告
//添加
public class ManageaddMsgServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String header = req.getParameter("title");
        String msgtype = req.getParameter("msgtype");
        if (Objects.equals(msgtype, "0")){
            msgtype="普通事件";
        }else {
            msgtype="重要事件";
        }
        String msgmember = req.getParameter("msgmember");
        msgmember= Objects.equals(msgmember, "0") ?"部分成员":"全体成员";
        String msgtext = req.getParameter("desc");
        Msgpojo msgpojo = new Msgpojo(0, header, msgtype, msgmember, msgtext, null);
        boolean b = new Manageserviceimpl().addmsgmanage(msgpojo);
        if (b){
            resp.getWriter().write("ok");
        }else {
            resp.getWriter().write("error");
        }
    }


//    删除用户信息表

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        boolean delmsg = new Manageserviceimpl().delusermsg(id);
        if (delmsg){
            resp.getWriter().write("ok");
        }else {
            resp.getWriter().write("error");
        }
    }
}
